﻿using System;

namespace UniRx.Operators
{
	// Token: 0x0200036E RID: 878
	internal class ZipLatestObservable<T1, T2, T3, TR> : OperatorObservableBase<TR>
	{
		// Token: 0x060011EE RID: 4590 RVA: 0x00051F04 File Offset: 0x00050304
		public ZipLatestObservable(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, ZipLatestFunc<T1, T2, T3, TR> resultSelector) : base(source1.IsRequiredSubscribeOnCurrentThread<T1>() || source2.IsRequiredSubscribeOnCurrentThread<T2>() || source3.IsRequiredSubscribeOnCurrentThread<T3>())
		{
			this.source1 = source1;
			this.source2 = source2;
			this.source3 = source3;
			this.resultSelector = resultSelector;
		}

		// Token: 0x060011EF RID: 4591 RVA: 0x00051F59 File Offset: 0x00050359
		protected override IDisposable SubscribeCore(IObserver<TR> observer, IDisposable cancel)
		{
			return new ZipLatestObservable<T1, T2, T3, TR>.ZipLatest(3, this, observer, cancel).Run();
		}

		// Token: 0x04000AAD RID: 2733
		private IObservable<T1> source1;

		// Token: 0x04000AAE RID: 2734
		private IObservable<T2> source2;

		// Token: 0x04000AAF RID: 2735
		private IObservable<T3> source3;

		// Token: 0x04000AB0 RID: 2736
		private ZipLatestFunc<T1, T2, T3, TR> resultSelector;

		// Token: 0x0200036F RID: 879
		private class ZipLatest : NthZipLatestObserverBase<TR>
		{
			// Token: 0x060011F0 RID: 4592 RVA: 0x000521AC File Offset: 0x000505AC
			public ZipLatest(int length, ZipLatestObservable<T1, T2, T3, TR> parent, IObserver<TR> observer, IDisposable cancel) : base(length, observer, cancel)
			{
				this.parent = parent;
			}

			// Token: 0x060011F1 RID: 4593 RVA: 0x000521CC File Offset: 0x000505CC
			public IDisposable Run()
			{
				this.c1 = new ZipLatestObserver<T1>(this.gate, this, 0);
				this.c2 = new ZipLatestObserver<T2>(this.gate, this, 1);
				this.c3 = new ZipLatestObserver<T3>(this.gate, this, 2);
				//IDisposable disposable = this.parent.source1.Subscribe(this.c1);
				//IDisposable disposable2 = this.parent.source2.Subscribe(this.c2);
				//IDisposable disposable3 = this.parent.source3.Subscribe(this.c3);
				//return StableCompositeDisposable.Create(disposable, disposable2, disposable3);
				return null;
			}

			// Token: 0x060011F2 RID: 4594 RVA: 0x0005225F File Offset: 0x0005065F
			public override TR GetResult()
			{
				return this.parent.resultSelector(this.c1.Value, this.c2.Value, this.c3.Value);
			}

			// Token: 0x060011F3 RID: 4595 RVA: 0x00052292 File Offset: 0x00050692
			public override void OnNext(TR value)
			{
				this.observer.OnNext(value);
			}

			// Token: 0x060011F4 RID: 4596 RVA: 0x000522A4 File Offset: 0x000506A4
			public override void OnError(Exception error)
			{
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x060011F5 RID: 4597 RVA: 0x000522DC File Offset: 0x000506DC
			public override void OnCompleted()
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x04000AB1 RID: 2737
			private readonly ZipLatestObservable<T1, T2, T3, TR> parent;

			// Token: 0x04000AB2 RID: 2738
			private readonly object gate = new object();

			// Token: 0x04000AB3 RID: 2739
			private ZipLatestObserver<T1> c1;

			// Token: 0x04000AB4 RID: 2740
			private ZipLatestObserver<T2> c2;

			// Token: 0x04000AB5 RID: 2741
			private ZipLatestObserver<T3> c3;
		}
	}
}
